package com.bjsxt.controller;


import com.bjsxt.domain.SysMenu;
import com.bjsxt.model.R;
import com.bjsxt.model.RolePrivilegeParam;
import com.bjsxt.service.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "角色的权限配置")
public class SysRolePrivilegeController {
    @Autowired
    private SysRolePrivilegeService sysRolePrivilegeService ;
    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色的Id")
    })
    public R<List<SysMenu>> getSysRolePrivilege(Long roleId){
       return R.ok(sysRolePrivilegeService.findSysMenuAndPrivileges(roleId)) ;

    }

    @GetMapping("/grant_privileges")
    @ApiOperation(value = "授予或者取消角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rolePrivilegeParam",value = "rolePrivilegeParam的json数据")
    })
    public R<List<SysMenu>> grantPrivileges(@RequestBody RolePrivilegeParam rolePrivilegeParam){
        boolean isOk = sysRolePrivilegeService.grantPrivilege(rolePrivilegeParam);
        if(isOk){
            return R.ok();
        }
        return R.fail("授予失败");
    }
}
